#pragma once

#include "qbe/src/ecs/plugin.hpp"
#include "qbe/src/ecs/stage.hpp"

#include "qbe/src/state/state.hpp"
#include "../../message/message.hpp"

#include "models.hpp"

namespace qbe::draw::AddRef {

class InitStage : public ecs::stage::after<ecs::stage::Startup> {};
class UpdateStage : public ecs::stage::after<state::UpdateStage> {};

void exit(ecs::Query query, state::AllModeType enter_mode);

void init(entt::registry& reg, ecs::Commands commands, ecs::Query query);
void update(entt::registry& ecs_reg, ecs::Query query, ecs::Bus& bus, ecs::EventWriter<msg::RenderEvent> event);
void post();


class AddRefPlugin : public ecs::Plugin {
 public:
  void build(ecs::App& app) {
    app.init_resource<AddRefModel>(AddRefModel{});
    app.add_stage<InitStage>();
    app.add_stage<UpdateStage>();

    app.add_systems<InitStage>(init);
    app.add_systems<UpdateStage>(update);
    app.add_systems<ecs::stage::PostUpdate>(post);
  }
};

}  // namespace qbe::draw::polygon